// 分页============================
const size = 20;
const startNum = 1;

/***
 *  @functione pageScroll 
 * @dedescription 页面分页
 **/
export const pageScroll = {
	data() {
		return {
			page: {
				page_no: startNum,
				page_size: size,
				count: size,
			},
			list: []
		};
	},

	onReachBottom() {
		if (this.page.count < this.page.page_no * this.page.page_size || this.page.count == this.page.page_no * this
			.page.page_size) {
			return
		}
		this.page.page_no = ++this.page.page_no
		this.init()
	},
	methods: {
		reset(e) {
			this.page = {
				page_no: startNum,
				page_size: size,
				count: size,
			}
			this.list = []
		},
	}
};
/***
 *  @functione scrollViewScroll 
 * @dedescription scrollView分页
 **/
export const scrollViewScroll = {
	data() {
		return {
			page: {
				page_no: startNum,
				page_size: size,
				count: size,
			},
			tabindex: 0,
			list: [],

		};
	},
	methods: {
		scrolltolower() {
			if (this.page.count < this.page.page_no * this.page.page_size || this.page.count == this.page.page_no *
				this
				.page.page_size) {
				return
			}
			this.page.page_no = ++this.page.page_no
			this.init()
		},
		async scrolltoupper() {
			this.$refs.paginationScrolling.refStart()
			this.reset();
			await this.init();
			this.$refs.paginationScrolling.refFinish()
		},
		tabChange({
			item,
			index
		}) {
			this.$emit('tabChange', {
				item,
				index
			})
		},
		reset(e) {
			this.page = {
				page_no: startNum,
				page_size: size,
				count: size,
			}
			this.list = []
		},
	}
};
/***
 *  @functione mapNav 
 * @dedescription 地图导航
 **/
export const mapNav = {
	methods: {
		navApp() {
			uni.showActionSheet({
				itemList: ['高德地图', '百度地图', '腾讯地图'],
				success: (res) => {
					this.guide(res.tapIndex);
				},
			});
		},
		guide(signMap) {
			uni.showLoading({
				title: '跳转中',
			});
			const fromData = this.fromData;
			if (fromData.name && fromData.name != '') {
				//地点位置position.name 地点经纬度lng lat
				var lng = fromData.longitude;
				var lat = fromData.latitude;
				if (signMap == 0) {
					// 高德地图
					uni.getSystemInfo({
						success: (res) => {
							if (res.platform === 'android') {
								window.location.href =
									'androidamap://viewMap?sourceApplication=appname&poiname=' +
									fromData.name + '&lat=' + lat + '&lon=' + lng + '&dev=0';
								//判断是否跳转
								setTimeout(function() {
									let hidden = window.document.hidden || window.document
										.mozHidden || window.document.msHidden || window
										.document.webkitHidden;
									if (typeof hidden == 'undefined' || hidden == false) {
										//调用高德地图
										window.location.href =
											'https://uri.amap.com/marker?position=' + lng +
											',' + lat + '&name=' + fromData.name;
									}
								}, 2000);
							} else {
								window.location.href =
									'iosamap://viewMap?sourceApplication=appname&poiname=' + fromData
									.name + '&lat=' + lat + '&lon=' + lng + '&dev=0';
								//判断是否跳转
								setTimeout(function() {
									let hidden = window.document.hidden || window.document
										.mozHidden || window.document.msHidden || window
										.document.webkitHidden;
									if (typeof hidden == 'undefined' || hidden == false) {
										//调用高德地图
										window.location.href =
											'https://uri.amap.com/marker?position=' + lng +
											',' + lat + '&name=' + fromData.name;
									}
								}, 2000);
							}
						},
					});
				} else if (signMap == 1) {
					// 百度地图
					uni.getSystemInfo({
						success: (res) => {
							if (res.platform === 'android') {
								let d = new Date();
								let t0 = d.getTime();
								window.location.href =
									'androidamap://viewMap?sourceApplication=appname&poiname=' +
									fromData.name + '&lat=' + lat + '&lon=' + lng + '&dev=0';
								//由于打开需要1～2秒，利用这个时间差来处理－－打开app后，返回h5页面会出现页面变成app下载页面，影响用户体验
								var delay = setInterval(function() {
									var d = new Date();
									var t1 = d.getTime();
									if (t1 - t0 < 3000 && t1 - t0 > 2000) {
										window.location.href =
											'http://api.map.baidu.com/marker?location=' + lat +
											',' + lng + '&title=' + fromData.name +
											'&content=地点&output=html&src=webapp.baidu.openAPIdemo';
									}
									if (t1 - t0 >= 3000) {
										clearInterval(delay);
									}
								}, 1000);
							} else {
								let d = new Date();
								let t0 = d.getTime();
								window.location.href =
									'iosamap://viewMap?sourceApplication=appname&poiname=' + fromData
									.name + '&lat=' + lat + '&lon=' + lng + '&dev=0';
								//由于打开需要1～2秒，利用这个时间差来处理－－打开app后，返回h5页面会出现页面变成app下载页面，影响用户体验
								let delay = setInterval(function() {
									var d = new Date();
									var t1 = d.getTime();
									if (t1 - t0 < 3000 && t1 - t0 > 2000) {
										window.location.href =
											'http://api.map.baidu.com/marker?location=' + lat +
											',' + lng + '&title=' + fromData.name +
											'&content=地点&output=html&src=webapp.baidu.openAPIdemo';
									}
									if (t1 - t0 >= 3000) {
										clearInterval(delay);
									}
								}, 1000);
							}
						},
					});
				} else {
					// 腾讯地图
					uni.getSystemInfo({
						success: (res) => {
							if (res.platform === 'android') {
								window.location.href =
									'androidamap://viewMap?sourceApplication=appname&poiname=' +
									fromData.name + '&lat=' + lat + '&lon=' + lng + '&dev=0';
								//判断是否跳转
								setTimeout(function() {
									let hidden = window.document.hidden || window.document
										.mozHidden || window.document.msHidden || window
										.document.webkitHidden;
									if (typeof hidden == 'undefined' || hidden == false) {
										//调用腾讯地图
										window.location.href =
											`https://apis.map.qq.com/uri/v1/marker?marker=coord:(${lat},${lng})&addr:${fromData.name}`;
									}
								}, 2000);
							} else {
								window.location.href =
									'iosamap://viewMap?sourceApplication=appname&poiname=' + fromData
									.name + '&lat=' + lat + '&lon=' + lng + '&dev=0';
								//判断是否跳转
								setTimeout(function() {
									let hidden = window.document.hidden || window.document
										.mozHidden || window.document.msHidden || window
										.document.webkitHidden;
									if (typeof hidden == 'undefined' || hidden == false) {
										//调用高德地图
										window.location.href =
											`https://apis.map.qq.com/uri/v1/marker?marker=coord:(${lat},${lng})&addr:${fromData.name}`;
									}
								}, 2000);
							}
						},
					});
				}
			} else {
				uni.showToast({
					title: '暂不知道该地点位置',
					icon: 'none',
					duration: 2000,
				});
			}
			setTimeout(function() {
				uni.hideLoading();
			}, 2000);
		},

	}
}